﻿using System;
using System.Threading.Tasks;
using DayDayUp.Core;
using DayDayUp.Core.Data;
using DayDayUp.Core.Domain.Posts;
using DayDayUp.Core.Domain.Users;

namespace DayDayUp.Service.Posts
{
    public class PostService : IPostService
    {
        private IMongoRepository<Post> _postRepository;
        private IMongoRepository<User> _userRepository;

        public PostService(IMongoRepository<Post> postRepository, IMongoRepository<User> userRepository)
        {
            _postRepository = postRepository;
            _userRepository = userRepository;
        }

        public Task<IPagedList<Post>> GetAllPosts(int userId)
        {
            throw new System.NotImplementedException();
        }

        public void SaveNewPost(string title, string description, string userId, string[] categories, bool isPublished)
        {

            var user = _userRepository.GetById(userId);

            var post = new Post()
            {
                Title = title,
                Description = description,
                Categories = categories,

                CreateOn = DateTime.Now,
                UpdatedOn = DateTime.Now,

                IsPublished = isPublished,
                User = user,
            };
            _postRepository.Save(post);

        }

        public void PublishPost(int postId)
        {
            throw new System.NotImplementedException();
        }
    }
}